#ifndef LOD_LOADER_H
#define LOD_LOADER_H

#include <fstream>
#include <utility>
#include <vector>

#include "jeff/mesh.h"

#include "base/error.h"
#include "object3d.h"

//! Data file loader
/*!
 * \param vtype Vertex type
 * \param cvtype Coloured vertex type
 * \param co_type Type that is used for storing coordinates
 * \param comp_type Type that is used for storing material parameters
 * \param it_type Type used for indices of vertices and materials*/
template<class vtype, class cvtype, class co_type, class comp_type, class it_type>
class loader
{
    public:
    //! Loads an object from *.tgt file
    /*! The data is added rather than swapped (i.e. if you load a mesh to an object
     * that already contains another mesh, it will result in concatanation).
     * \param path Path to a file.
     * \param object Reference to an object intended to store the data.*/
    error load_tgt(const char* path, 
               object3d<vtype,cvtype,co_type,comp_type,it_type> & object,
               bool clear_3d_object=true);
    error load_ply(char* path, jeff::Mesh** mesh, bool clear_mesh);

    private:
    static const int MAX_VERTS = int(10e6/sizeof(double)); // 10 MB of vertices
    static const int MAX_CVERTS = int(10e6/sizeof(double)); // 10 MB of coloured 
                                                            //         vertices
    static const int MAX_TRIANGLES = int(20e6/sizeof(int)); // 20 MB of triangles

    static const int MAX_CTRIANGLES = int(20e6/sizeof(int)); // 20 MB of coloured 
                                                            //          triangles
    static const int MAX_MATERIALS = 64;
    static const int LINE_LEN = 256;

    static const char* MATERIAL_MODES[];
    static const int MAT_MODES_COUNT;
    
    //private:
    //! Handles errors in file access.
    error file_error(const std::istream & fin, int line_nr);
};

#include "loader.cpp"

#endif // LOD_LOADER_H
